using System;
using System.Text.RegularExpressions;
using SpCop.Core.Model;

namespace SpCop.Model
{
    /// <summary>
    /// Represents a part of the content of a MixedContentFile.
    /// </summary>
    public class ContentPart
    {
        /// <summary>
        /// Constructs a ContentPart.
        /// </summary>
        /// <param name="file">The file.</param>
        /// <param name="type">The type.</param>
        /// <param name="offset">The offset.</param>
        /// <param name="length">The length.</param>
        /// <param name="match">The match.</param>
        public ContentPart(MixedContentFile file, int type, int offset, int length, Match match)
            : this(file, (MixedContentTypes)type, offset, length, match)
        {
          
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="ContentPart"/> class.
        /// </summary>
        /// <param name="file">The file.</param>
        /// <param name="type">The type.</param>
        /// <param name="offset">The offset.</param>
        /// <param name="length">The length.</param>
        /// <param name="match">The match.</param>
        public ContentPart(MixedContentFile file, MixedContentTypes type, int offset, int length, Match match) 
        {
           
            File = file;
            Type = type;
            Offset = offset;
            Length = length;
            Match = match;
        }

        /// <summary>
        /// File of this part.
        /// </summary>
        public MixedContentFile File { get; set; }

        /// <summary>
        /// Type of the part.
        /// </summary>
        public MixedContentTypes Type { get; set; }

        /// <summary>
        /// Character position in file at which this part starts.
        /// </summary>
        public int Offset { get; set; }

        /// <summary>
        /// Length (number of charaters) of this part.
        /// </summary>
        public int Length { get; set; }

        /// <summary>
        /// Full text content rerpesented by this part.
        /// </summary>
        public string Content
        {
            get
            {
                
                return File.Content.Substring(Offset, Length);
            }
        }

        /// <summary>
        /// Additional data related to this part.
        /// </summary>
        public Match Match { get; set; }

        public override string ToString()
        {
            return string.Format("{0} {1}", Type, Content);
        }

       

    
    }
}